import QtQuick 2.6
import QtQuick.Controls 1.5
import QtQuick.Layouts 1.1

import Cpp.Request 1.0 as Request

Column {
    Component.onCompleted: login.login("testUserAdmin", "0403")
    function loginClicked()
    {
        login.login(usernameInput.text, passwordInput.text)
    }

    RowLayout {
        Label {
            text: qsTr("username")
        }
        TextField {
            id: usernameInput
        }
    }
    RowLayout {
        Label {
            text: qsTr("password")
        }
        TextField {
            id: passwordInput
            onAccepted: loginClicked()
        }
    }
    Button {
        id:loginButton
        isDefault: true
        text: qsTr("login")
        enabled: login.status !== Request.Login.Communicating
        onClicked: loginClicked()
    }

    Request.Login {
        id:login
        onOk: {
            app.setStatus(qsTr("Login successed."))
        }
        onFailed : {
            app.setStatus(qsTr("Login failed : username or password error!"))
        }
        onError: {
            app.setStatus(qsTr("Login error : %1").arg(errorString))
        }
    }
}
